<?php
/**
 * // TODO
 * 
 * @version $Id: TaobaokeController.php 621 2013-01-01 05:30:19Z linsir123 $
 */
class TaobaokeController extends AppController 
{
	/**
	 * @var 模型
	 */
	public $mTerm;
	
	/**
	 * @var 参数列表
	 */
	public $data = array();
	
	/**
	 * @var 对应的淘宝客参数
	 */
	public $taobaoke = array();
	
	/**
	 * @var 排序说明
	 */
	public $sorts = array();
	
	/**
	 * @var 清除关键字
	 */
	public $cleanKeyword = false;
	
	/**
	 * @var 0=>list,1=>zhe,2=>shops
	 */
	public $listType = 0;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		parent::__construct();
		
		///
		$this->mTerm = M::terms();
	}
	
	/**
	 * 构造查询链接
	 */
	protected function _createUrl($params = array())
	{
		$params = array_merge($this->data, $params);
		
		///
		if ($this->cleanKeyword) 
			$params['keyword'] = 0;
			
		///
		switch ($this->listType) {
			case 1:
				$url = Route::urlZhe($params);
				break;
			case 2:
				$url = Route::urlShops($params);
				break;
			default:
				$url = Route::urlClass($params);
				break;
		}
		return $url;
	}
	
	/**
	 * 内部重定向
	 */
	protected function _h301($params = array())
	{
		$url = $this->_createUrl($params);
		///
		lpSystem::h301($url);
		///
		exit();
	}
	
	/**
	 * 排序信息
	 */
	protected function _aSortInfo()
	{
		$tmp = "";
		$format = $this->_createUrl(array('p'=>1, 'sort'=>'__SORT__'));
		foreach ($this->sorts as $i => $v) {
			if ($this->data['sort'] == $i) {
				$class = 'class="this"';
				$href = '#';
			} else {
				$class = '';
				$href = str_replace('__SORT__', $i, $format);
			}
			$tmp .= '<li '. $class .'><a href="'. $href .'">'. $v[0] .'</a></li>';
		}
		///
		return $tmp;
	}
	
	/**
	 * 分页
	 */
	protected function _aPagination($totalPage)
	{
		$url = $this->_createUrl(array('p'=>'__PAGE__'));
		
		///
		$com = App::C('Pagination', 
			$url, 
			$this->data['p'], 
			$totalPage, 
			8, 
			array(
			'pre'=>'上一页', 
			'next'=>'下一页')
		);
		$com->setUrlPStyle(1);
		return $com->display();
	}
}
